﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LView.CMS.IServices;
using LView.CMS.Core.Extensions;

namespace LView.CMS.Services
{
    public class ClaimsAccessorService : IClaimsAccessorService
    {
        protected IPrincipalAccessorService PrincipalAccessor { get; }
        public ClaimsAccessorService(IPrincipalAccessorService principalAccessor)
        {
            PrincipalAccessor = principalAccessor;
        }
        public string UserID
        {
            get
            {
                var userID = PrincipalAccessor.Principal.Claims.FirstOrDefault(x => x.Type == "ID").Value;
                if (!userID.IsNullOrEmpty())
                {
                    return userID;
                }
                return null;
            }
        }

        public string RoleID
        {
            get
            {
                var roleID = PrincipalAccessor.Principal.Claims.FirstOrDefault(x => x.Type == "RoleID").Value;
                if (!roleID.IsNullOrEmpty())
                {
                    return roleID;
                }
                return null;
            }
        }

        public string NickName
        {
            get
            {
                var nickName = PrincipalAccessor.Principal.Claims.FirstOrDefault(x => x.Type == "NickName").Value;
                if (!nickName.IsNullOrEmpty())
                {
                    return nickName;
                }
                return null;
            }
        }

        public string UserName
        {
            get
            {
                var userName = PrincipalAccessor.Principal.Claims.FirstOrDefault(x => x.Type == "UserName").Value;
                if (!userName.IsNullOrEmpty())
                {
                    return userName;
                }
                return null;
            }
        }
    }
}
